package com.university.mentalhealthplatform.studentV3.dto;

import com.university.mentalhealthplatform.global.rbac.dto.normal.RoleDTO;
import com.university.mentalhealthplatform.global.rbac.model.User;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

@Getter
@Setter
@NoArgsConstructor
public class UserDTOV3 {

    // Getters 和 Setters

    private UUID id;
    private String username;
    private boolean status;
    private Set<RoleDTO> roles;
    private String nickname;
    private String department;
    private String phone;
    private String password;

    // 静态方法将 User 转换为 UserDTOV3
    public static UserDTOV3 fromUser(User user) {
        UserDTOV3 userDTO = new UserDTOV3();
        userDTO.setId(user.getId());
        userDTO.setUsername(user.getUsername());
        userDTO.setStatus(user.isStatus());

        // 将所有 Role 转换为 RoleDTO
        userDTO.setRoles(user.getRoles().stream()
                .map(RoleDTO::fromRole) // 假设 RoleDTO 有 fromRole 静态方法
                .collect(Collectors.toSet())); // 将 Role 转换为 RoleDTO 集合

        return userDTO;
    }

    public UserDTOV3(UUID id, String username, boolean status) {
        this.id = id;
        this.username = username;
        this.status = status;
    }

    // 构造方法
    public UserDTOV3(UUID id, String username, boolean status, Set<RoleDTO> roles) {
        this.id = id;
        this.username = username;
        this.status = status;
        this.roles = roles;
    }


}
